<!--
 * @Descripttion: 佣金记录
 * @Author: xiao li
 * @Date: 2020-09-24 16:38:42
 * @LastEditors: xiao li
 * @LastEditTime: 2021-04-29 18:09:31
-->
<template>
    <div>
        <top-nav></top-nav>
        <div class="page-main">

        <div class="page-search-form">
          <el-form @submit.native.prevent :inline="true" :model="searchForm" ref="searchForm">
            <el-form-item label="输入查询" prop="name">
              <el-input placeholder="用户昵称/用户手机号" v-model="searchForm.name"></el-input>
            </el-form-item>
            <el-form-item label="返佣类型" prop="thing_type">
              <el-select v-model="searchForm.thing_type" filterable clearable placeholder="请选择">
                <el-option
                  v-for="item in levelList"
                  :key="item.id"
                  :label="item.title"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="时间查询" prop="range">
              <el-date-picker
                v-model="searchForm.range"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
                value-format="timestamp"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <lb-button size="medium" type="primary"  icon="el-icon-search" style="margin-right:5px" @click="getTableDataList(1)" >{{$t('action.search')}}</lb-button>
              <lb-button size='medium' icon="el-icon-refresh-left" style="margin-right:5px" @click="resetForm('searchForm')" >{{$t('action.reset')}}</lb-button>
            </el-form-item>
          </el-form>
        </div>
          <el-table
              v-loading='loading'
              :data="tableData"
              :header-cell-style="{background:'#f5f7fa',color:'#606266'}"
              style="width: 100%">
                <el-table-column
                  prop="nickName"
                  label="用户昵称">
                </el-table-column>
                <el-table-column
                  prop="phone"
                  label="用户手机号">
                </el-table-column>
                <el-table-column
                  prop="source_name"
                  label="佣金来源">
                </el-table-column>
                <el-table-column
                  prop="out_trade_no"
                  label="订单编号"
                 >
                </el-table-column>
                <el-table-column
                  prop="price"
                  label="订单金额(元)"
                 >
                </el-table-column>
                <el-table-column
                  prop="selling_type"
                  label="返佣方式"
                 >
                  <template slot-scope="scope">
                      <p>{{scope.row.selling_type === 1  ? `固定金额 ¥${scope.row.extract_cash}` : `百分比 ${scope.row.extract}%`}}</p>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="moeny"
                  label="返佣金额(元)"
                 >
                </el-table-column>
                <el-table-column
                  prop="price"
                  label="返佣类型"
                 >
                  <template slot-scope="scope">
                      <p>{{scope.row.thing_type === 1 ? '购买套餐' : scope.row.thing_type === 2 ? '员工扣款' : '系统扣款'}}</p>
                  </template>
                </el-table-column>
                <el-table-column
                  prop='create_time'
                  label="创建时间"
                 >
                  <template slot-scope="scope">
                      <p>{{scope.row.create_time | handleTime(1)}}</p>
                      <p>{{scope.row.create_time | handleTime(2)}}</p>
                  </template>
                </el-table-column>
          </el-table>
          <lb-page
            :batch='false'
            :page='searchForm.page'
            :pageSize='searchForm.limit'
            :total='total'
            @handleSizeChange='handleSizeChange'
            @handleCurrentChange='handleCurrentChange'
            >
          </lb-page>
        </div>

    </div>
</template>

<script>
export default {
  data () {
    return {
      loading: false,
      searchForm: {
        page: 1,
        limit: 10,
        name: '',
        thing_type: '',
        range: ''
      },
      levelList: [{
        id: 0,
        title: '全部'
      }, {
        id: 1,
        title: '购买套餐'
      }, {
        id: 2,
        title: '员工扣款'
      }, {
        id: 3,
        title: '系统扣款'
      }],
      tableData: [],
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() > Date.now()
        }
      },
      total: 0,
      showDialog: {
        growth: false,
        stored: false,
        record: false
      },
      dialogForm: {
        key: ''
      }
    }
  },
  activated () {
    this.getTableDataList()
  },
  methods: {
    toResetForm () {
      this.$refs.multipleTable.clearSelection()
    },
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    getTableDataList (flag) {
      if (flag) this.searchForm.page = 1
      this.loading = true
      let param = this.$util.pick(this.searchForm, [
        'page',
        'limit',
        'name',
        'thing_type'
      ])
      let {range = ''} = this.searchForm
      if (range) {
        param.start_time = range[0] / 1000
        param.end_time = range[1] / 1000 + 24 * 3600 - 1
      }
      this.$api.memberWaterList(param).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.data.data
          this.total = res.data.total
        }
      })
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    }
  },
  filters: {
    handleTime (val, type) {
      let time = type === 1 ? moment(val * 1000).format('YYYY-MM-DD') : type === 2 ? moment(val * 1000).format('HH:mm:ss') : moment(val * 1000).format('YYYY-MM-DD HH:mm:ss')
      return time
    }
  }
}
</script>

<style lang="scss" scoped>
.el-select,
.el-input{
  width: 200px;
}
</style>
